<template>
  <div>
    <v-md-preview :text="text"></v-md-preview>
    <div>
      <el-button type="primary" size="default" @click="getDocument3">直开PDF</el-button>
      <iframe :src="src" frameborder="0"></iframe>
    </div>
  </div>
</template>

<script>
  import { getMdUrl, getMdByOutPutStream, getMdByOutPutStream2 } from '@http/api';
  import axios from 'axios';
  import { encrypto } from './cryptoMy';
  export default {
    data() {
      return {
        text: '',
        src: '',
      };
    },
    components: {},
    created() {
      // this.getDocument();
      this.getDocument2();
    },
    mounted() {},
    methods: {
      // 通过URL形式获取md文件
      getDocument() {
        getMdUrl({ objectName: encrypto('todo/README1.md') }).then(res => {
          axios({
            method: 'get',
            url: res.data.data,
          }).then(md => {
            console.log(md.data);
            this.text = md.data;
          });
        });
      },

      // 通过文件流形式获取md文件
      getDocument2() {
        // 请求接口
        getMdByOutPutStream({ bucketName: 'mahuaide', objectName: 'todo/README1.md' }).then(res => {
          this.text = res.data;
        });
      },

      // 通过文件流形式获取md文件
      getDocument3() {
        // 请求接口
        getMdByOutPutStream2({ bucketName: 'mahuaide', objectName: '2.pdf' }).then(res => {
          let responseData = res.data;
          let blob = new Blob([responseData], { type: 'application/pdf;charset=utf-8' });
          const href = URL.createObjectURL(blob);
          window.open(href + '#scrollbars=0&toolbar=0&statusbar=0', 'newWindow');
        });
      },
    },
  };
</script>
